package cn.wolfcode.p2p.business.service.impl;
import cn.wolfcode.p2p.business.domain.ActiveWater;
import cn.wolfcode.p2p.business.mapper.ActiveWaterMapper;
import cn.wolfcode.p2p.business.service.IActiveWaterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class ActiveWaterServiceImpl implements IActiveWaterService {

    @Autowired
    private ActiveWaterMapper activeWaterMapper;


    @Override
    public void createActiveWater() {
        ActiveWater activeWater = new ActiveWater();
        activeWater.setActionTime(new Date());
        activeWater.setActionType(1);
        activeWater.setAmount(new BigDecimal("1000"));
        activeWaterMapper.insert(activeWater);
        log.debug("创建流水");
    }

    @Override
    public Map<String, BigDecimal> statistics() {
        Map<String,BigDecimal> map = new HashMap<>();
        //统计收入
        BigDecimal income = activeWaterMapper.listAmountByType(2);
        map.put("income",income);
        //统计支出
        BigDecimal expenses = activeWaterMapper.listAmountByType(1);
        map.put("expenses",expenses);
        return map;
    }

}
